<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="更新" width="600px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
      <el-form-item label="ID:" prop="evaluate_id">
        <el-input v-model="form.evaluate_id" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="评论人:" prop="nick">
        <el-input v-model="form.nick" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="图片:" prop="icon_url">
        <el-input v-model="form.icon_url" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="等级:" prop="level">
        <el-input v-model="form.level" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="创建时间:" prop="create_date">
        <el-input v-model="form.create_date" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="状态:" prop="state">
        <el-input v-model="form.state" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="标题:" prop="pro_title">
        <el-input v-model="form.pro_title" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="评论:" prop="activity_details">
        <el-input v-model="form.activity_details" style="width: 370px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { edit } from '@/api/evluate4'
export default {
  components: { },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        'evaluate_id': '',
        'nick': '',
        'icon_url': '',
        'level': '',
        'create_date': '',
        'state': '',
        'pro_title': '',
        'activity_details': ''
      },
      rules: {
        evaluate_id: [
          { required: true, message: '请输入ID', trigger: 'blur' }
        ],
        nick: [
          { required: true, message: '请输入评论人', trigger: 'blur' }
        ],
        icon_url: [
          { required: true, message: '请输入图片', trigger: 'blur' }
        ],
        level: [
          { required: true, message: '请输入等级', trigger: 'blur' }
        ],
        create_date: [
          { required: true, message: '请输入创建时间', trigger: 'blur' }
        ],
        state: [
          { required: true, message: '请输入状态', trigger: 'blur' }
        ],
        pro_title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        activity_details: [
          { required: true, message: '请输入评论', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // 表单验证
      this.$refs['form'].validate((valid) => {
        // 通过
        if (valid) {
          this.doAdd()
        }
      })
    },

    doAdd() {
      edit(this.form).then(() => {
        this.resetForm()
        this.$notify({
          title: '更新成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(() => {
        this.loading = false
      })
    },

    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        'evaluate_id': '',
        'nick': '',
        'icon_url': '',
        'level': '',
        'create_date': '',
        'state': '',
        'pro_title': '',
        'activity_details': ''
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
